// SIP Configuration Types
export interface SipConfig {
  server: string;
  port: number;
  username: string;
  password: string;
  transport: TransportType;
  display_name?: string;
  local_port?: number;
}

export enum TransportType {
  UDP = "UDP",
  TCP = "TCP",
  TLS = "TLS",
  Auto = "Auto",
}

export enum RegistrationStatus {
  Unregistered = "Unregistered",
  Registering = "Registering", 
  Registered = "Registered",
  Failed = "Failed",
  AuthenticationFailed = "AuthenticationFailed",
  NetworkError = "NetworkError", 
  TimeoutError = "TimeoutError",
}

export interface ConnectionTestResult {
  success: boolean;
  transport_used: TransportType;
  response_time?: number;
  error_message?: string;
}

export interface NetworkStatus {
  is_connected: boolean;
  active_transport?: TransportType;
  local_address?: string;
  server_address?: string;
}

// Call Management Types
export interface CallInfo {
  id: string;
  remote_number: string;
  remote_name?: string;
  direction: CallDirection;
  status: CallStatus;
  start_time?: string;
  duration?: number;
}

export enum CallDirection {
  Inbound = "Inbound",
  Outbound = "Outbound",
}

export enum CallStatus {
  Ringing = "Ringing",
  Connected = "Connected",
  Ended = "Ended",
  Failed = "Failed",
}

export interface IncomingCallInfo {
  call_id: string;
  caller_number: string;
  caller_name?: string;
}

// Audio Types
export interface AudioDevice {
  id: string;
  name: string;
  is_default: boolean;
}

export interface AudioDevices {
  input_devices: AudioDevice[];
  output_devices: AudioDevice[];
  current_input?: string;
  current_output?: string;
}

export interface AudioLevels {
  input_level: number;
  output_level: number;
  is_muted: boolean;
}

export interface AudioConfig {
  input_device?: string;
  output_device?: string;
  input_volume: number;
  output_volume: number;
  echo_cancellation: boolean;
  noise_suppression: boolean;
}

export interface AudioDeviceInfo {
  id: string;
  name: string;
  is_default: boolean;
  supported_sample_rates: number[];
  supported_channels: number[];
  supported_formats: string[];
}

export interface AudioStreamConfig {
  sample_rate: number;
  channels: number;
  buffer_size: number;
  format: string;
}

// Enhanced Audio Stream Types
export enum AudioCodec {
  PCMU = "PCMU", // G.711 μ-law
  PCMA = "PCMA", // G.711 A-law
}

export interface AudioStreamSettings {
  codec: AudioCodec;
  sample_rate: number;
  channels: number;
  frame_size: number; // samples per frame
  packet_time: number; // milliseconds
}

export interface AudioQualitySettings {
  echo_cancellation: boolean;
  noise_suppression: boolean;
  automatic_gain_control: boolean;
  jitter_buffer_size: number;
  packet_loss_concealment: boolean;
  adaptive_bitrate: boolean;
}

export interface AudioQualityMetrics {
  input_level: number;
  output_level: number;
  packet_loss_rate: number;
  jitter: number;
  round_trip_time?: number; // milliseconds
  packets_sent: number;
  packets_received: number;
  packets_lost: number;
  bytes_sent: number;
  bytes_received: number;
}

// Configuration Types
export interface UiConfig {
  theme: string;
  language: string;
  window_width: number;
  window_height: number;
  auto_answer: boolean;
}

export interface AppConfig {
  sip?: SipConfig;
  audio: AudioConfig;
  ui: UiConfig;
}

// Event Types
export interface RegistrationEvent {
  status: RegistrationStatus;
  message?: string;
  retry_count?: number;
  next_retry_in?: number; // seconds
  error_code?: string;
  server_response?: string;
  timestamp: number; // Unix timestamp
}

export interface IncomingCallEvent {
  call_id: string;
  caller_number: string;
  caller_name?: string;
}

export interface CallStatusEvent {
  call_id: string;
  status: CallStatus;
  duration?: number;
}

export interface AudioStatusEvent {
  call_id: string;
  muted: boolean;
  volume_level: number;
}